#!/usr/bin/env python3

# Copyright (c) 2020-2021 Fpemud <fpemud@sina.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.


from .._vm import VmConfig


class Spec:

    # from "General Setup Options / Desktop" tab in application "Microsoft Batch 98"
    # I think it is the real desktop icon names
    _optionalDesktopIconList = [
        "My Documents",
        "Connect to Internet",                              # FIXME: no effect?
        "Network Neighbourhood",
        "Internet Explorer & Outlook Express",              # FIXME: no effect?
        "Recycle Bin",
        "Setup the Microsoft Network",                      # FIXME: it is "Setup MSN Internet Access"?
    ]

    # from "Optional Components" in application "Microsoft Batch 98"
    # I think it is the real component names, default values and dependencies
    _bOptionalComponentDict = {
        # Accessibility Options
        "Accessibility Options":         True,
        "Accessibility Tools":           False,
        # Accessories
        "Briefcase":                     False,
        "Calculator":                    True,
        "Desktop Wallpaper":             False,
        "Document Templates":            True,
        "Games":                         False,
        "Imaging":                       True,
        "Mouse Pointers":                False,
        "Paint":                         True,
        "Quick View":                    False,
        "Windows Scripting Host":        True,
        "WordPad":                       True,
        # Address Book
        "Address Book":                  True,
        # Communications
        "Dial-Up ATM Support":           False,   # depends on "Dial-Up Networking"
        "Dial-Up Networking":            False,
        "Dial-Up Server":                False,   # depends on "Dial-Up Networking"
        "Direct Cable Connection":       False,   # depends on "Dial-Up Networking"
        "HyperTerminal":                 False,
        "Microsoft Chat 2.5":            False,
        "NetMeeting":                    True,
        "Phone Dialer":                  True,
        "Virtual Private Networking":    False,   # depends on "Dial-Up Networking"
        # Desktop Themes
        "Baseball":                      False,
        "Dangerous Creatures":           False,
        "Inside your Computer":          False,
        "Jungle":                        False,
        "Leonardo da Vinci":             False,
        "More Windows":                  False,
        "Mystery":                       False,
        "Nature":                        False,
        "Science":                       False,
        "Space":                         False,
        "Sports":                        False,
        "The 60\'s USA":                 False,
        "The Golden Era":                False,
        "Travel":                        False,
        "Underwater":                    False,
        "Windows 98":                    False,
        "Desktop Themes Support":        False,           # ?
        # Internet Tools
        "Internet Connection Sharing":   False,
        "Microsoft Wallet":              False,
        "Personal Web Server":           True,
        "Web Publishing Wizard":         False,
        "Web-Based Enterprise Mgmt":     False,
        # Microsoft Outlook Express
        "Microsoft Outlook Express":     True,
        # Multilanguage Support
        "Baltic":                        False,
        "Central European":              False,
        "Cyrillic":                      False,
        "Greek":                         False,
        "Turkish":                       False,
        # Multimedia
        "Audio Compression":             True,
        "CD Player":                     True,
        "Macromedia Shockwave Director": True,
        "Macromedia Shockwave Flash":    True,
        "Multimedia Sound Schemes":      False,
        "Sample Sounds":                 False,
        "Sound Recorder":                True,
        "Video Compression":             True,
        "Volume Control":                True,
        # Online Services
        "America Online":                True,
        "AT&T WorldNet Service":         True,
        "CompuServe":                    True,
        "Prodigy Internet":              True,
        "The Microsoft Network":         True,
        # Screen Savers
        "Additional Screen Savers":      False,
        "Flying Windows":                True,
        "OpenGL Screen Savers":          False,
        # System Tools
        "Backup":                        False,
        "Character Map":                 False,
        "Clipboard Viewer":              False,
        "Disk compression tools":        True,
        "Drive Converter (FAT32)":       True,
        "Group policies":                False,
        "Net Watcher":                   False,
        "System Monitor":                False,
        "System Resource Meter":         False,
        # Web TV for Windows
        "Web TV for Windows":            False,
        "WaveTop Data Broadcasting":     False,   # depends on "Dial-Up Networking"
    }

    _timeZoneDict = {
        "Dateline":         "(GMT-12:00) Eniwetok:Kwajalein",
        "Samoa":            "(GMT-11:00) Midway Island:Samoa",
        "Hawaiian":         "(GMT-10:00) Hawaii",
        "Alaskan":          "(GMT-09:00) Alaska",
        "Pacific":          "(GMT-08:00) Pacific Time (US & Canada); Tijuana",
        "US Mountain":      "(GMT-07:00) Arizona",
        "Mountain":         "(GMT-07:00) Mountain Time (US & Canada)",
        "Central":          "(GMT-06:00) Central Time (US & Canada)",
        "Mexico":           "(GMT-06:00) Mexico City, Tegucigalpa",
        "Canada Central":   "(GMT-06:00) Saskatchewan",
        "SA Pacific":       "(GMT-05:00) Bogota, Lima",
        "Eastern":          "(GMT-05:00) Eastern Time (US & Canada)",
        "US Eastern":       "(GMT-05:00) Indiana (East)",
        "Atlantic":         "(GMT-04:00) Atlantic Time (Canda)",
        "SA Western":       "(GMT-04:00) Caracas, La Paz",
        "Newfoundland":     "(GMT-03:30) Newfoundland",
        "E. South America": "(GMT-03:00) Brasilia",
        "SA Eastern":       "(GMT-03:00) Buenos Aires, Georgetown",
        "Mid-Atlantic":     "(GMT-02:00) Mid-Atlantic",
        "Azores":           "(GMT-01:00) Azores, Cape Verde Is.",
        "Greenwich":        "(GMT) Casablanca, Monrovia",
        "GMT":              "(GMT) Greenwich Mean Time : Bublin, Edinburgh, Lisbon, London",
        "W. Europe":        "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
        "Balkan":           "(GMT+01:00) Beograd, Ljubljana, Sarajevo, Skoplje, Sofija, Zagreb",
        "Central Europe":   "(GMT+01:00) Bratislava, Budapest, Prague, Warsaw",
        "Romance":          "(GMT+01:00) Brussels, Madrid, Paris",
        "GT":               "(GMT+02:00) Athens, Istanbul",
        "Egypt":            "(GMT+02:00) Cairo",
        "E. Europe":        "(GMT+02:00) E. Europe",
        "South Africa":     "(GMT+02:00) Harare, Pretoria",
        "Finland":          "(GMT+02:00) Helsinki",
        "Israel":           "(GMT+02:00) Israel",
        "Saudi Arabia":     "(GMT+03:00) Baghdad, Kuwait, Nairobi, Riyadh",
        "Russian":          "(GMT+03:00) Kazan, Moscow, St. Petersburg, Volgograd",
        "Iran":             "(GMT+03:30) Tehran",
        "Arabian":          "(GMT+04:00) Abu Dhabi, Muscat",
        "Tbilisi":          "(GMT+04:00) Tbilisi",
        "Afghanistan":      "(GMT+04:30) Kabul",
        "Ekaterinburg":     "(GMT+05:00) Ekaterinburg",
        "West Asia":        "(GMT+05:00) Islamabad, Karachi, Tashkent",
        "India":            "(GMT+05:30) Bombay, Calcutta, Madras, New Delhi",
        "Central Asia":     "(GMT+06:00) Almaty, Dhaka",
        "Colombo":          "(GMT+06:00) Colombo",
        "Bangkok":          "(GMT+07:00) Bangkok",
        "Hanoi":            "(GMT+07:00) Hanoi",
        "Jakarta":          "(GMT+07:00) Jakarta",
        "China":            "(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi",
        "W. Australia":     "(GMT+08:00) Perth",
        "Singapore":        "(GMT+08:00) Singapore",
        "Taipei":           "(GMT+08:00) Taipei",
        "Tokyo":            "(GMT+09:00) Osaka, Sapporo, Tokyo",
        "Korea":            "(GMT+09:00) Seoul",
        "Yakutsk":          "(GMT+09:00) Yakutsk",
        "Cen. Australia":   "(GMT+09:30) Adelaide",
        "AUS Central":      "(GMT+09:30) Darwin",
        "AUS Eastern":      "(GMT+10:00) Brisbane",
        "E. Australia":     "(GMT+10:00) Canberra, Melbourne, Sydney",
        "West Pacific":     "(GMT+10:00) Guam, Port Moresby",
        "Tasmania":         "(GMT+10:00) Hobart",
        "Vladivostok":      "(GMT+10:00) Vladivostok",
        "Central Pacific":  "(GMT+11:00) Magadan, Soloman Is., New Caledonia",
        "New Zealand":      "(GMT+12:00) Auckland, Wellington",
        "Fiji":             "(GMT+12:00) Fiji, Kamchatka, Marshall Is.",
    }

    _keyboardLayoutDict = {
        "Albanian":                         "KEYBOARD_0000041C",
        "Arabic (Algeria) 101":             "KEYBOARD_00001401",
        "Arabic (Algeria) 102":             "KEYBOARD_00011401",
        "Arabic (Algeria) 102 Azerty":      "KEYBOARD_00021401",
        "Arabic (Bahrain) 101":             "KEYBOARD_00003C01",
        "Arabic (Bahrain) 102":             "KEYBOARD_00013C01",
        "Arabic (Bahrain) 102 Azerty":      "KEYBOARD_00023C01",
        "Arabic (Egypt) 101":               "KEYBOARD_00000C01",
        "Arabic (Egypt) 102":               "KEYBOARD_00010C01",
        "Arabic (Egypt) 102 Azerty":        "KEYBOARD_00020C01",
        "Arabic (Iraq) 101":                "KEYBOARD_00000801",
        "Arabic (Iraq) 102":                "KEYBOARD_00010801",
        "Arabic (Iraq) 102 Azerty":         "KEYBOARD_00020801",
        "Arabic (Jordan) 101":              "KEYBOARD_00002C01",
        "Arabic (Jordan) 102":              "KEYBOARD_00012C01",
        "Arabic (Jordan) 102 Azerty":       "KEYBOARD_00022C01",
        "Arabic (Kuwait) 101":              "KEYBOARD_00003401",
        "Arabic (Kuwait) 102":              "KEYBOARD_00013401",
        "Arabic (Kuwait) 102 Azerty":       "KEYBOARD_00023401",
        "Arabic (Lebanon) 101":             "KEYBOARD_00003001",
        "Arabic (Lebanon) 102":             "KEYBOARD_00013001",
        "Arabic (Lebanon) 102 Azerty":      "KEYBOARD_00023001",
        "Arabic (Libya) 101":               "KEYBOARD_00001001",
        "Arabic (Libya) 102":               "KEYBOARD_00011001",
        "Arabic (Libya) 102 Azerty":        "KEYBOARD_00021001",
        "Arabic (Morocco) 101":             "KEYBOARD_00001801",
        "Arabic (Morocco) 102":             "KEYBOARD_00011801",
        "Arabic (Morocco) 102 Azerty":      "KEYBOARD_00021801",
        "Arabic (Oman) 101":                "KEYBOARD_00002001",
        "Arabic (Oman) 102":                "KEYBOARD_00012001",
        "Arabic (Oman) 102 Azerty":         "KEYBOARD_00022001",
        "Arabic (Qatar) 101":               "KEYBOARD_00004001",
        "Arabic (Qatar) 102":               "KEYBOARD_00014001",
        "Arabic (Qatar) 102 Azerty":        "KEYBOARD_00024001",
        "Arabic (Saudi Arabia) 101":        "KEYBOARD_00000401",
        "Arabic (Saudi Arabia) 102":        "KEYBOARD_00010401",
        "Arabic (Saudi Arabia) 102 Azerty": "KEYBOARD_00020401",
        "Arabic (Syria) 101":               "KEYBOARD_00002801",
        "Arabic (Syria) 102":               "KEYBOARD_00012801",
        "Arabic (Syria) 102 Azerty":        "KEYBOARD_00022801",
        "Arabic (Tiunisia) 101":            "KEYBOARD_00001C01",
        "Arabic (Tiunisia) 102":            "KEYBOARD_00011C01",
        "Arabic (Tiunisia) 102 Azerty":     "KEYBOARD_00021C01",
        "Arabic (UAE) 101":                 "KEYBOARD_00003801",
        "Arabic (UAE) 102":                 "KEYBOARD_00013801",
        "Arabic (UAE) 102 Azerty":          "KEYBOARD_00023801",
        "Arabic (Yemen) 101":               "KEYBOARD_00002401",
        "Arabic (Yemen) 102":               "KEYBOARD_00012401",
        "Arabic (Yemen) 102 Azerty":        "KEYBOARD_00022401",
        "Belarusian":                       "KEYBOARD_00000423",
        "Belgian (Comma)":                  "KEYBOARD_0001080C",
        "Belgian (Period)":                 "KEYBOARD_0000080C",
        "British":                          "KEYBOARD_00000809",
        "Bulgarian":                        "KEYBOARD_00000402",
        "Bulgarian (Latin)":                "KEYBOARD_00000402",
        "Canadian Multilingual":            "KEYBOARD_00001009",
        "Canadian Standard":                "KEYBOARD_00011009",
        "Croatian":                         "KEYBOARD_0000041A",
        "Czech":                            "KEYBOARD_00000405",
        "Czech (Programmers)":              "KEYBOARD_00020405",
        "Czech (Qwerty)":                   "KEYBOARD_00010405",
        "Danish":                           "KEYBOARD_00000406",
        "Dutch":                            "KEYBOARD_00000413",
        "Estonian":                         "KEYBOARD_00000425",
        "Faeroe Islands":                   "KEYBOARD_00000438",
        "Finnish":                          "KEYBOARD_0000040B",
        "French":                           "KEYBOARD_0000040C",
        "French Canadian":                  "KEYBOARD_00000C0C",
        "German (IBM)":                     "KEYBOARD_00010407",
        "German (Standard)":                "KEYBOARD_00000407",
        "Greek":                            "KEYBOARD_00000408",
        "Greek IBM 220":                    "KEYBOARD_00010408",
        "Greek IBM 319":                    "KEYBOARD_00030408",
        "Greek Latin":                      "KEYBOARD_00050408",
        "Greek Latin IBM 220":              "KEYBOARD_00020408",
        "Greek Latin IBM 319":              "KEYBOARD_00040408",
        "Hebrew 101":                       "KEYBOARD_0000040D",
        "Hebrew 102":                       "KEYBOARD_0001040D",
        "Hebrew 102 Azerty":                "KEYBOARD_0002040D",
        "Hungarian":                        "KEYBOARD_0000040E",
        "Hungarian (101 keys)":             "KEYBOARD_0001040E",
        "Icelandic":                        "KEYBOARD_0000040F",
        "Irish":                            "KEYBOARD_00001809",
        "Italian":                          "KEYBOARD_00000410",
        "Italian 142":                      "KEYBOARD_00010410",
        "Japan keyboards":                  "KEYBOARD_00000411",
        "Korea keyboards":                  "KEYBOARD_00000412",
        "Latin American":                   "KEYBOARD_0000080A",
        "Latvian":                          "KEYBOARD_00000426",
        "Latvian (Latin)":                  "KEYBOARD_00010426",
        "Lithuanian (IBM)":                 "KEYBOARD_00000427",
        "Macedonia (FYROM)":                "KEYBOARD_0000042F",
        "Norwegian":                        "KEYBOARD_00000414",
        "Polish":                           "KEYBOARD_00000415",
        "Polish (Programmers)":             "KEYBOARD_00010415",
        "Portuguese (Brazilian ABNT2)":     "KEYBOARD_00010416",
        "Portuguese (Brazilian standard)":  "KEYBOARD_00000416",
        "Portuguese (Standard)":            "KEYBOARD_00000816",
        "PRC keyboards":                    "KEYBOARD_00000409",
        "Romanian":                         "KEYBOARD_00000418",
        "Russian":                          "KEYBOARD_00000419",
        "Russian (Typewriter)":             "KEYBOARD_00010419",
        "Serbian":                          "KEYBOARD_00000C1A",
        "Serbian (Latin)":                  "KEYBOARD_00010C1A",
        "Slovak":                           "KEYBOARD_0000041B",
        "Slovak (Qwerty)":                  "KEYBOARD_0001041B",
        "Slovenian":                        "KEYBOARD_00000424",
        "Spanish Modern":                   "KEYBOARD_00000C0A",
        "Spanish Traditional":              "KEYBOARD_0000040A",
        "Swedish":                          "KEYBOARD_0000041D",
        "Swiss French":                     "KEYBOARD_0000100C",
        "Swiss German":                     "KEYBOARD_00000807",
        "Taiwan keyboards":                 "KEYBOARD_00000409",
        "Turkish (F type)":                 "KEYBOARD_0001041F",
        "Turkish (Q type)":                 "KEYBOARD_0000041F",
        "Ukrainian":                        "KEYBOARD_00000422",
        "United State 101":                 "KEYBOARD_00000409",
        "United States-Dvorak":             "KEYBOARD_00020409",
        "United States-International":      "KEYBOARD_00010409",
        "United States-LH Dvorak":          "KEYBOARD_00030409",
        "United States-RH Dvorak":          "KEYBOARD_00040409",
    }

    _localeDict = {
        "Afrikaans":                        "L0436",
        "Albanian":                         "L041C",
        "Arabic (Algeria)":                 "L1401",
        "Arabic (Bahrain)":                 "L3C01",
        "Arabic (Egypt)":                   "L0C01",
        "Arabic (Iraq)":                    "L0801",
        "Arabic (Jordan)":                  "L2C01",
        "Arabic (Kuwait)":                  "L3401",
        "Arabic (Lebanon)":                 "L3001",
        "Arabic (Libya)":                   "L1001",
        "Arabic (Morocco)":                 "L1801",
        "Arabic (Oman)":                    "L2001",
        "Arabic (Qatar)":                   "L4001",
        "Arabic (Saudi Arabia)":            "L0401",
        "Arabic (Syria)":                   "L2801",
        "Arabic (Tunisia)":                 "L1C01",
        "Arabic (U.A.E)":                   "L3801",
        "Arabic (Yemen)":                   "L2401",
        "Basque":                           "L042D",
        "Belarusian":                       "L0423",
        "Bulgarian":                        "L0402",
        "Catalan":                          "L0403",
        "Croatian":                         "L041A",
        "Czech":                            "L0405",
        "Danish":                           "L0406",
        "Dutch (Belgian)":                  "L0813",
        "Dutch (Standard)":                 "L0413",
        "English (Australian)":             "L0C09",
        "English (British)":                "L0809",
        "English (Canadian)":               "L1009",
        "English (Caribbean)":              "L2409",
        "English (Ireland)":                "L1809",
        "English (Jamaica)":                "L2009",
        "English (New Zealand)":            "L1409",
        "English (South Africa)":           "L1C09",
        "English (United States)":          "L0409",
        "Estonian":                         "L0425",
        "Finnish":                          "L040B",
        "French (Belgian)":                 "L080C",
        "French (Canadian)":                "L0C0C",
        "French (Luxembourg)":              "L140C",
        "French (Standard)":                "L040C",
        "French (Swiss)":                   "L100C",
        "German (Austrian)":                "L0C07",
        "German (Liechtenstein)":           "L1407",
        "German (Luxembourg)":              "L1007",
        "German (Standard)":                "L0407",
        "German (Swiss)":                   "L0807",
        "Greek (MS-DOS CodePage 737 (43))": "L0408B",
        "Greek (MS-DOS CodePage 737)":      "L0408",
        "Greek (MS-DOS CodePage 869 (85))": "L0408D",
        "Greek (MS-DOS CodePage 869)":      "L0408C",
        "Hebrew":                           "L040D",
        "Hungarian":                        "L040E",
        "Icelandic":                        "L040F",
        "Indonesian":                       "L0421",
        "Italian (Standard)":               "L0410",
        "Italian (Swiss)":                  "L0810",
        "Japan":                            "L0411",
        "Korea":                            "L0412",
        "Latvian":                          "L0426",
        "Lithuanian":                       "L0427",
        "Macedonia (FYROM)":                "L042F",
        "Norwegian (Bokmal)":               "L0414",
        "Norwegian (Nynorsk)":              "L04814",
        "Polish":                           "L0415",
        "Portuguese (Brazilian)":           "L0416",
        "Portuguese (Standard)":            "L0816",
        "PRC":                              "L0804",
        "Romanian":                         "L0418",
        "Russian":                          "L0419",
        "Serbian":                          "L0C1A",
        "Slovak":                           "L041B",
        "Slovenian":                        "L0424",
        "Spanish (Argentina)":              "L2C0A",
        "Spanish (Chile)":                  "L340A",
        "Spanish (Colombia)":               "L240A",
        "Spanish (Costa Rica)":             "L140A",
        "Spanish (Dominican Republic)":     "L1C0A",
        "Spanish (Ecuador)":                "L300A",
        "Spanish (Guatemala)":              "L100A",
        "Spanish (Mexico)":                 "L0C80A",
        "Spanish (Modern Sort)":            "L0C0A",
        "Spanish (Panama)":                 "L180A",
        "Spanish (Paraguay)":               "L3C0A",
        "Spanish (Peru)":                   "L280A",
        "Spanish (Traditional Sort)":       "L040A",
        "Spanish (Uruguay)":                "L380A",
        "Spanish (Venezuela)":              "L200A",
        "Swedish":                          "L041D",
        "Taiwan":                           "L0404",
        "Turkish":                          "L041F",
        "Ukrainian":                        "L0422",
    }

    def getOptionalComponentList(self):
        return list(self._bOptionalComponentDict.keys())

    def getOptionalComponentDefaultValueDict(self):
        return self._bOptionalComponentDict

    def getOptionalDesktopIconList(self):
        return self._optionalDesktopIconList

    def getTimeZoneList(self):
        return list(self._timeZoneDict.keys())

    def getTimeZoneDescription(self, timezone):
        return self._timeZoneDict[timezone]

    def getKeyboardLayoutList(self):
        return list(self._keyboardLayoutDict.keys())

    def getKeyboardLayoutValue(self, keyboardLayout):
        return self._keyboardLayoutDict[keyboardLayout]

    def getLocaleList(self):
        return list(self._localeDict.keys())

    def getLocaleValue(self, locale):
        return self._localeDict[locale]

    def getMainDiskSize(self):
        return "1G"

    def getStorageLayoutName(self):
        return "bios-fat16"

    def getWindowsDir(self):
        return "C:\\WINDOWS"

    def getVmConfig(self):
        return VmConfig(qemu_vm_type="pc",
                        cpu_arch="x86",
                        cpu_number=1,
                        memory_size="32M",
                        bios_type="bios",
                        disk_interface="ide",
                        network_type="none")            # win98's network driver has some obstacles, and currently no app (mainly old games) uses network in win98

    def getScreenInfoBootstrap(self):
        return (640, 480, 16)       # 640x480 resolution, 16bit color

    def getScreenInfoFinal(self):
        return (640, 480, 16)       # 640x480 resolution, 16bit color

    def getDefaultScreenSaverTimeout(self):
        return 60 * 15              # default timeout is 5 minutes
